﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace Estimate
{
    public partial class formAdminUser : FormMDIChildTemplate 
    {
        public formAdminUser()
        {
            InitializeComponent();
            
        }

       

        private void formAdminUsers_Load(object sender, EventArgs e)
        { FillGrid(); }

        private void gridUsers_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
        {
            string s = e.Value as string;
            UserRule userRule =
                (from x in userRulebindingSource.OfType<UserRule>() where x.ToString() == s select x).FirstOrDefault();
            e.Value = userRule;
            e.ParsingApplied = true;
        }

        private void saveToolStripButton_Click_1(object sender, EventArgs e)
        { root.Submit(); FillGrid(); }

        private void FillGrid()
        {
            var users = context.Users.Where(x => x.UserID > 0).Select(x => x);
            var userRules = context.UserRules.Where(x => x.UserRuleID > 0).Select(x => x);
            userRulebindingSource.DataSource = userRules.ToList();
            userBindingSource.DataSource = users;
            root.TranslateGrid(gridUsers);

        }
    }
}
